package com.example.weatherapp.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.weatherapp.R;
import com.example.weatherapp.beans.DailyItemBean;
import com.example.weatherapp.utils.WeatherUtil;

import java.util.List;

public class DailyAdapter extends RecyclerView.Adapter<DailyAdapter.RVHolder> {

    private List<DailyItemBean> datas;

    public DailyAdapter(List<DailyItemBean> datas) {
        this.datas = datas;
    }

    @NonNull
    @Override
    public RVHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_daily, parent, false);
        return new RVHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RVHolder holder, int position) {
        holder.tvWeek.setText(datas.get(position).getWeek());
        holder.tvDate.setText(datas.get(position).getDate());
        holder.ivSkycon.setImageResource(WeatherUtil.genIconBySkycon(datas.get(position).getSkycon()));
        holder.tvSkycon.setText(WeatherUtil.genDescriptionBySkycon(datas.get(position).getSkycon()));
        holder.tvTempMax.setText(datas.get(position).getTempMax());
        holder.tvTempMin.setText(datas.get(position).getTempMin());
    }


    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class RVHolder extends RecyclerView.ViewHolder {
        private TextView tvWeek;
        private TextView tvDate;
        private ImageView ivSkycon;
        private TextView tvSkycon;
        private TextView tvTempMax;
        private TextView tvTempMin;

        public RVHolder(@NonNull View itemView) {
            super(itemView);
            tvWeek = itemView.findViewById(R.id.tvWeek);
            tvDate = itemView.findViewById(R.id.tvDate);
            ivSkycon = itemView.findViewById(R.id.ivSkycon);
            tvSkycon = itemView.findViewById(R.id.tvSkycon);
            tvTempMax = itemView.findViewById(R.id.tvTempMax);
            tvTempMin = itemView.findViewById(R.id.tvTempMin);
        }
    }
}
